﻿-- =============================================
-- Script Template
-- =============================================
USE [DB_Ex]
GO

/****** Object:  StoredProcedure [dbo].[sp_1C_Get_Returns_Filter]    Script Date: 12/05/2011 10:38:56 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_1C_Get_Returns_Filter]
(
  @parSklad varchar(100) = NULL
, @parCompany varchar(100) = NULL
)
AS
BEGIN
SET NOCOUNT ON;

	IF(@parSklad IS NOT NULL AND @parCompany IS NOT NULL)
	BEGIN
		SELECT TOP 2000 [_Number], [DT] ,[Sklad] ,[Kontragent] ,[Sum] FROM [DB_Ex].[dbo].[vw_1C_Get_Returns]
		Where (Sklad = @parSklad) AND (Kontragent = @parCompany)
	END
	ELSE
	BEGIN
		IF(@parSklad IS NOT NULL AND @parCompany IS NULL)
		BEGIN
			SELECT TOP 2000 [_Number], [DT] ,[Sklad] ,[Kontragent] ,[Sum] FROM [DB_Ex].[dbo].[vw_1C_Get_Returns]
			Where (Sklad = @parSklad)
		END
		ELSE
		BEGIN
			IF(@parSklad IS NULL AND @parCompany IS NOT NULL)
			BEGIN
				SELECT TOP 2000 [_Number], [DT] ,[Sklad] ,[Kontragent] ,[Sum] FROM [DB_Ex].[dbo].[vw_1C_Get_Returns]
				Where (Kontragent = @parCompany)
			END
			ELSE
			BEGIN
				SELECT TOP 2000 [_Number], [DT] ,[Sklad] ,[Kontragent] ,[Sum] FROM [DB_Ex].[dbo].[vw_1C_Get_Returns]		
			END
		
		END
	END

END

GO


